//
//  CinemaCell.m
//  UI 作业 - 豆瓣电影
//
//  Created by hesiyao on 15/12/22.
//  Copyright © 2015年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "CinemaCell.h"

@implementation CinemaCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.img = [[UIImageView alloc] init];
        [self.contentView addSubview:_img];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.img addSubview:_titleLabel];
//        _titleLabel.backgroundColor = [UIColor magentaColor];
        _titleLabel.numberOfLines = NO;
        
        self.addressLabel = [[UILabel alloc] init];
        [self.img addSubview:_addressLabel];
//        _addressLabel.backgroundColor = [UIColor magentaColor];
        _addressLabel.numberOfLines = NO;
        
        self.phoneLabel = [[UILabel alloc] init];
        [self.img addSubview:_phoneLabel];
//        _phoneLabel.backgroundColor = [UIColor magentaColor];
        _phoneLabel.numberOfLines = NO;
        
        
    }
    return self;
}

+ (CGFloat)heightWithTitle:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(375 - 20, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

+ (CGFloat)heightWithAddress:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(375 - 20, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

+ (CGFloat)heightWithPhone:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(375 - 20, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    _img.frame = CGRectMake(20, 20, self.contentView.frame.size.width - 40, self.contentView.frame.size.height - 40);
    CGFloat h = [[self class] heightWithTitle:_titleLabel.text];
    _titleLabel.frame = CGRectMake(10, 10, self.img.frame.size.width - 20, h);
    CGFloat h1 = [[self class] heightWithAddress:_addressLabel.text];
    _addressLabel.frame = CGRectMake(10, 70, self.img.frame.size.width - 20, h1);
    CGFloat h2 = [[self class] heightWithPhone:_phoneLabel.text];
    _phoneLabel.frame = CGRectMake(10, 120, self.img.frame.size.width - 20, h2);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
